#!/usr/bin/python3
# -*- coding: utf-8 -*
"""
Description: log config.
Class: LogConfig
"""
import os
import configparser

from . import global_config
from ..system_config import SYSTEM_CONFIG_PATH


class LogConfig():
    """
    Merge system default configuration with configuration file.
    """

    def __init__(self):
        """
        Class instance initialization.
        """
        for config in dir(global_config):
            setattr(self, config, getattr(global_config, config))

        if not os.path.exists(SYSTEM_CONFIG_PATH):
            return

        self.conf = configparser.RawConfigParser()
        self.conf.read(SYSTEM_CONFIG_PATH)

        if 'aparser' not in self.conf.sections():
            return

        for option in self.conf.items('aparser'):
            try:
                key = option[0]
                value = option[1]
            except IndexError:
                pass
            else:
                if not value:
                    continue
                if value.isdigit():
                    value = int(value)
                elif value.lower() in ('true', 'false'):
                    value = bool(value)
                setattr(self, key.upper(), value)


configuration = LogConfig()
